from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SKUImage, SKU
from meiduo_admin.serializers.images import SKUImageSerializer,SKUSerializer
from meiduo_admin.utils import PageNum


class ImageView(ModelViewSet):
    # 指定查询集
    queryset = SKUImage.objects.filter()
    # 指定序列化器
    serializer_class = SKUImageSerializer
    # 指定权限
    permission_classes = [IsAdminUser]
    # 指定分页器
    pagination_class = PageNum


    # 获取sku表的所有id值
    # 自定义方法 获取sku商品数据
    def simple(self, request):
        # 1.查询所有spu表数据
        skus = SKU.objects.all()
        # 2.序列化返回
        ser = SKUSerializer(skus, many=True)

        return Response(ser.data)
